<template>
	<!-- banner -->
	<view>
		<up-swiper :list="list1" indicator indicatorMode="dot" height="180" previousMargin="30"
                nextMargin="30" circular radius="5"></up-swiper>
	</view>
	<view>
	  <up-notice-bar :text="text1"></up-notice-bar>
	</view>
	<!-- 分类 -->
	<view>
		<up-tabs :list="list2" lineWidth="20" lineHeight="7" :lineColor="`url(${lineBg}) 100% 100%`" :activeStyle="{
		        color: '#303133',
		        fontWeight: 'bold',
		        transform: 'scale(1.05)'
		    }" :inactiveStyle="{
		        color: '#606266',
		        transform: 'scale(1)'
		    }" itemStyle="padding:0 15px; height: 40px;" @click="addRandomData"></up-tabs>
	</view>
	<!-- 商品展示 -->
	<view>
		<up-waterfall v-model="flowList" ref="uWaterfallRef">
			<template v-slot:left="{leftList}">
				<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
					<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
					<up-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></up-lazy-load>
					<view class="demo-title">
						{{item.title}}
					</view>
					<view class="demo-price">
						{{item.price}}元
					</view>
					<view class="demo-tag">
						<view class="demo-tag-owner">
							自营
						</view>
						<view class="demo-tag-text">
							放心购
						</view>
					</view>
				</view>
			</template>
			<template v-slot:right="{rightList}">
				<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
					<up-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></up-lazy-load>
					<view class="demo-title">
						{{item.title}}
					</view>
					<view class="demo-price">
						{{item.price}}元
					</view>
					<view class="demo-tag">
						<view class="demo-tag-owner">
							自营
						</view>
						<view class="demo-tag-text">
							放心购
						</view>
					</view>
				</view>
			</template>
		</up-waterfall>
	</view>
</template>

<script setup>
	import {
		reactive,
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import { shuffleArray } from '/util'
	
	let uWaterfallRef = ref()
	let text1 = ref("众多新款商品上新中，敬请期待！！")

	// 使用 reactive 创建响应式数组  
	const list1 = reactive([
		'https://cdn.uviewui.com/uview/swiper/swiper1.png',
		'https://cdn.uviewui.com/uview/swiper/swiper2.png',
		'https://cdn.uviewui.com/uview/swiper/swiper3.png',
	]);
	const lineBg =
		"";
	// 创建响应式数据  
	const list2 = reactive([{
			name: '推荐'
		},
		{
			name: '电影'
		},
		{
			name: '科技',
			badge: {
				isDot: true
			}
		},
		{
			name: '音乐'
		},
		{
			name: '美食'
		},
		{
			name: '文化'
		},
		{
			name: '财经'
		},
		{
			name: '手工'
		}
	]);


	let flowList = ref([])

	const list = reactive([{
			price: 35,
			title: '北国风光，千里冰封，万里雪飘',
			image: 'http://resources.codeinn.cn/img-1.png',
		},
		{
			price: 75,
			title: '望长城内外，惟余莽莽',
			image: 'http://resources.codeinn.cn/img-2.png',
		},
		{
			price: 385,
			title: '大河上下，顿失滔滔',
			image: 'http://resources.codeinn.cn/img-3.png',
		},
		{
			price: 784,
			title: '欲与天公试比高',
			image: 'http://resources.codeinn.cn/img-4.png',
		},
		{
			price: 7891,
			title: '须晴日，看红装素裹，分外妖娆',
			image: 'http://resources.codeinn.cn/img-5.png',
		},
		{
			price: 2341,
			title: '江山如此多娇，引无数英雄竞折腰',
			image: 'http://resources.codeinn.cn/img-6.png',
		},
		{
			price: 661,
			title: '惜秦皇汉武，略输文采',
			image: 'http://resources.codeinn.cn/img-7.png',
		},
		{
			price: 1654,
			title: '唐宗宋祖，稍逊风骚',
			image: 'http://resources.codeinn.cn/img-8.png',
		},
		{
			price: 1678,
			title: '一代天骄，成吉思汗',
			image: 'http://resources.codeinn.cn/img-9.png',
		},
		{
			price: 924,
			title: '只识弯弓射大雕',
			image: 'http://resources.codeinn.cn/img-10.png',
		},
		{
			price: 8243,
			title: '俱往矣，数风流人物，还看今朝',
			image: 'http://resources.codeinn.cn/t (1).png',
		}
	])
	onLoad(() => {
		addRandomData()
	})

	const addRandomData = () => {
		let arr = shuffleArray(list)
		let newArr = []
		for (let i = 0; i < arr.length; i++) {
			let item = JSON.parse(JSON.stringify(arr[i]))
			item.id = uni.$u.guid();
			newArr.push(item);
		}
		flowList.value = newArr
	}
</script>

<style scoped lang="scss">
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 25rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-primary;
		color: $u-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 25rpx;
		color: $u-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>